package com.lemon.smartsafetynew.net.services;

import android.content.Context;

import com.lemon.android.http.LemonRequestParams;
import com.lemon.smartsafety.app.Constants;
import com.lemon.smartsafety.app.IApplication;
import com.lemon.smartsafety.app.RefreshType;
import com.lemon.smartsafety.http.UrlInfo;
import com.lemon.smartsafety.http.callback.HandlerCallback;
import com.lemon.smartsafety.http.service.BaseHttpServices;
import com.lemon.smartsafetynew.entity.contact.DepartmentVo;
import com.lemon.smartsafetynew.entity.contact.PersonVo;
import com.lemon.smartsafetynew.util.constants.KeyConstants;
import com.zhy.http.okhttp.OkHttpUtils;

import java.util.List;

/**
 * Created by Andrew on 2017/9/12.
 */

public class ContactServices extends BaseHttpServices {

    public static final String TAG = "ContactServices";

    public ContactServices(Context context) {
        super(context);
    }

    /**
     * 初始化，等同使用构造函数
     *
     * @return
     */
    public static ContactServices init() {
        return new ContactServices(IApplication.context());
    }


    /**
     * 初始化，等同使用构造函数
     *
     * @param context
     * @return
     */
    public static ContactServices init(Context context) {
        return new ContactServices(context);
    }

    /**
     * 获取部门
     */
    @Deprecated
    public void getDepartment(RefreshType refreshType, LemonRequestParams params) {

        HandlerCallback<List<DepartmentVo>> callback = new HandlerCallback<List<DepartmentVo>>(KeyConstants.URL_GET_COMPANY_DEPARTMENT) {
        };
        callback.setOther(refreshType);
        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.GET_COMPANY_DEPARTMENT);
        OkHttpUtils.post()
                .tag(callback.getTag())
                .url(serverUrl)
                .params(params)
                .build().execute(callback);

    }

    /**
     * 获取企业中的联系人
     */
    public void getUserFromDepartment(RefreshType refreshType, LemonRequestParams params) {

        HandlerCallback<List<PersonVo>> callback = new HandlerCallback<List<PersonVo>>(KeyConstants.URL_GET_COMPANY_PERSON) {
        };
        callback.setOther(refreshType);
        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.GET_COMPANY_PERSON, Constants.SERVER_V2);
        OkHttpUtils.post()
                .tag(callback.getTag())
                .url(serverUrl)
                .params(params)
                .build().execute(callback);

    }

    /**
     * 获取所有的联系人
     */
    public void getAllUser(LemonRequestParams params) {

        HandlerCallback<List<PersonVo>> callback = new HandlerCallback<List<PersonVo>>(KeyConstants.URL_GET_ALL_PERSON) {
        };
        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.GET_ALL_PERSON, Constants.GSAFE);
        OkHttpUtils.post()
                .tag(callback.getTag())
                .url(serverUrl)
                .params(params)
                .build().execute(callback);

    }

    /**
     * 获取所有的联系人
     */
    public void getGovGridLeader(LemonRequestParams params) {

        HandlerCallback<List<PersonVo>> callback = new HandlerCallback<List<PersonVo>>(KeyConstants.URL_GET_GOV_GRID_LEAD) {
        };
        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.GET_GOV_GRID_LEAD, Constants.GSAFE);
        OkHttpUtils.post()
                .tag(callback.getTag())
                .url(serverUrl)
                .params(params)
                .build().execute(callback);

    }
}
